package com.coolwen.controller;

import com.coolwen.entity.User;
import com.coolwen.service.GoodsTypeService;
import com.coolwen.service.GroupService;
import com.coolwen.service.OrderService;
import com.coolwen.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;

/**
 * Created by Eoly on 2016/12/7.
 */
@Controller
@SessionAttributes("loginUser")
public class InitController {

    @Autowired
    GoodsTypeService goodsTypeService;

    @Autowired
    OrderService orderService;

    @Autowired
    UserService userService;

    @Autowired
    GroupService groupService;

    /**
     * 初始化测试首页（默认测试用户）
     * @param model
     * @return
     */
    @RequestMapping("/test-init")
    public String testInit(Model model){
        User loginUser = new User();

        /*此处添加微信用户识别唯一api活动openId
            loginUser.setOpenId();
            ...
         */

        //判断用户是否录入

        //添加用户若未录入添加用户

        //若录入则通过id获得实体对象

        //测试用户
        loginUser = userService.findByUserId(1);

        //添加用户到session实体
        model.addAttribute("loginUser",loginUser);

        //获得类型列表
        model.addAttribute("types",goodsTypeService.findAllGoodsType());

        //获得团列表
        model.addAttribute("groups",groupService.findAllGroup());

        return "/web/index";
    }

    /**
     * 初始化首页
     * @param model
     * @return
     */
    @RequestMapping("/login-user/index")
    public String Init(Model model){


        //获得类型列表
        model.addAttribute("types",goodsTypeService.findAllGoodsType());

        //获得团列表
        model.addAttribute("groups",groupService.findAllGroup());

        return "/web/index";
    }
}
